package com.example.hand.doamin.entity;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

/**
 * Lab2：LocalDate、LocalTime、LocalDateTime、DateTimeFormatter的使用
 */
public class Lab2 {
    public static void main(String[] args) {

        //1.获取当前日期、格式化日期为“yyyyMMdd”、当期日期加10天
        method1();

        // 2. 获取当前时间、格式化日期为“yyyy/MM/dd HH:mm:ss.SSS”，当前时间减1小时
        method2();

        // 3. 比较两个日期的大小
        method3();

    }


    private static void method1() {

        //获取当前时间
        LocalDate currentDate = LocalDate.now();
        System.out.println("当前时间日期：" + currentDate);

        // 格式化日期
        //自定义格式化的格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyMMdd");
        String formatData = currentDate.format(formatter);
        System.out.println("格式化日期：" + formatData);

        //当期日期加10天
        LocalDate plusDays = currentDate.plusDays(10);
        System.out.println("增加10天的日期：" + plusDays);

    }

    private static void method2() {

        //获取当前时间
        LocalDateTime curDate = LocalDateTime.now();
        System.out.println("当前时间日期：" + curDate);

        //格式化日期
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss.SSS");
        String formatDate = curDate.format(formatter);
        System.out.println("格式化日期：" + formatDate);

        //当前时间减1小时
        LocalDateTime minusHours = curDate.minusHours(1);
        System.out.println("减1小时的时间：" + minusHours);


    }


    private static void method3() {

        LocalDate time1 = LocalDate.now();
        LocalDate time2 = LocalDate.of(2022, 5, 20);

        if (time1.isBefore(time2)) {
            System.out.println("time1 is before time2");
        } else {
            System.out.println("time1 is after time2");
        }


    }


}
